package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"github.com/gin-gonic/gin"
	"basic2/basic/web/controller"
	swaggerfiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	_ "basic2/docs"
)

var (
	confFile = flag.String("conf_file", "./conf/connector.toml", "path to configuration file")
)

type ProgramConfig struct {
	AdminListenAddr string `toml:"admin_listen_addr"`
	ClusterName     string `toml:"cluster_name"`
}

//@title go WEB
//@version 1.0
//@description 这是一个伟大的开始
//@termsOfService http://swagger.io/terms/
//@contact.name 1091979637
//@contact.url http://www.swagger.io/support
//@contact.email support@swagger.io
//@license.name Apache 2.0
//@license.url http://www.apache.org/licenses/LICENSE-2.0.html
//@host localhost
//@BasePath /
func main() {
	r := gin.Default()
	// Swagger 配置
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
	r.GET("/start", controller.Start)
	r.Run(":8090")
	//读取配置文件
	//var config ProgramConfig
	//meta, _ := toml.DecodeFile(*confFile, &config)
	////toml.DecodeFile("./conf/connector.toml", &config)
	//if meta.IsDefined("datapaths", "adaptor") {
	//	fmt.Println("true")
	//}
	//fmt.Println(meta.Keys())
	//fmt.Println(DumpJsonBrief(config))
	//fmt.Println("Hello, World!")
}

func DumpJson(something interface{}) string {
	bs, err := json.MarshalIndent(something, "", "    ")
	if err != nil {
		return err.Error()
	}
	return string(bs)
}

func DumpJsonBrief(something interface{}) string {
	bs, err := json.Marshal(something)
	if err != nil {
		return err.Error()
	}
	return string(bs)
}

func buildP(p *ProgramConfig) ProgramConfig {
	fmt.Println(1)
	fmt.Println(p)
	fmt.Println(2)
	return ProgramConfig{}
}
